package com.线程;


/**
 * 会有线程安全问题 案例
 */
public class 卖票 {

    public static void main(String[] args) {

        Ticket ticket = new Ticket();

        for(int i = 0 ; i <3;i++){

            new Thread(ticket,"售票处"+(i+1)).start();
        }
    }


}

class Ticket implements Runnable{

    private  int ticket = 300 ;

    @Override
    public void run() {



        while(true){

            if(ticket>0){


                System.out.println(Thread.currentThread().getName()+"准备出票:"+"当前票数为:"+ticket);

                ticket--;

                System.out.println(Thread.currentThread().getName()+"出票了,剩余票数:"+ticket);


            }else {
                break;
            }

        }




    }
}
